This page last changed on Jan 08, 2008 by [email protected].

GeoServer with Tomcat and Postgresql on CentOS 5.x

How to install GeoServer on CentOS 5.x (also valid for Red Hat 5.x), including Postgresql with Postgis support.


These instructions are written for CentOS 5.1, which is a distribution built on the source packages of Red Hat Enterprise Linux 5.1. I recommend a minimal install. The key thing to avoid GCJ and other Java implementations. If you deselect everything during installation you can get away with only using the first CD of seven. Choose the AMD64 version if your computer supports it.

Download and copy the latest version of Java 1.6 to the server (the .bin file, not the RPM). The AMD64 version should technically provide you with better performance on a 64 bit server, but it is known to have bugs. If you experience problems  (Java crashes) or emphasize stability you should pick the i586 version.

cd /opt
sh /path/to/jdk-1_6_0_XX-linux-i586.bin

This will install Java in some subdirectory of /opt . Create a symlink to make it more userfriendly:

ln -s jdk1.6.0_03 sun-java-1.6.0

Install required packages

yum install postgresql postgresql-server postgresql-devel gcc gcc-c++ libXp libXtst make bzip2 flex

Install Java

CentOS / Red Hat ship with Tomcat 5.5. It works allright, but for better control, and to avoid GCJ we'll install our own.

First we'll create a user that can run tomcat

useradd \-m tomcat

Note we don't set a password for tomcat, because we don't want this user to be able to login. Instead we'll use

su -l tomcat

Do that now, next set up the environment to run java:

echo "export JAVA_HOME=/opt/sun-java-1.6.0" >> .bashrc
echo "export PATH=/opt/sun-java-1.6.0/bin:$PATH" >> .bashrc
echo "export MALLOC_CHECK_=0" >> .bashrc

The last line is due to problems with double freeing of memory in the Java Virtual Machine, in particular the 2D rendering code. 

Switch back to the user for the new settings to take effect

su -l tomcat
java -version

The last command should respond with

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)

or something similar.

Install Apache Tomcat 

Now installing Tomcat is as easy as grabbing the archive and unpacking it:
Download from http://tomcat.apache.org
cd /opt
Unpack

tar xzvf /path/to/apache-tomcat-6.0.14.tar.gz

Now we'll make the tomcat user the owner of the directory
chown tomcat apache-tomcat-6.0.14 -R
Make another symlink

ln -s apache-tomcat-6.0.14 tomcat-6.0

Now we'll switch to tomcat again and see whether it works. Make sure you have nothing running on port 8080:

su -l tomcat
cd /opt/tomcat-6.0/bin
./catalina.sh start

If you have a problem, first check port 8080 (as root):

netstat -nptl

Try connecting to your server at port 8080, http://servername:8080
You should be greeted by a Apache Tomcat page. If not, make sure you're not running a firewall or that it is set to let port 8080 pass.

Now you need to add a user to
/opt/tomcat-6.0/conf/tomcat-users.xml

The following file defines a user "admin" with password "geoserver:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="geoserver" roles="manager"/>
</tomcat-users>

Restart Tomcat, then go to http://yourserver:8080/manager/html
Find the section "WAR file to deploy" and upload the .war file, which you can download from the GeoServer website.

GeoServer should now be available if you go to http://yourserver:8080/geoserver

Finally, edit /opt/tomcat-6.0/conf/server.xml. Uncomment the sections

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>

and

<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Comment out

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

GeoServer willl work without this, but Tomcat will only respond to one request at a time.

Postgresql with PostGIS support:

Option 1: Install GEOS

Download from http://geos.refractions.net/
cd /usr/local/src
tar xjvf /path/to/geos-2.2.3.tar.bz2
cd geos-2.2.3
./configure
make
make install

At least for GEOS you need to put the library someplace Postgresql will find it, or symlink:

ln -s /usr/local/lib/libgeos_c.so /usr/lib64/libgeos_c.so
ln -s /usr/local/lib/libgeos_c.so.1 /usr/lib64/libgeos_c.so.1
ln -s /usr/local/lib/libproj.so.0 /usr/lib64/libproj.so.0

Note that this assumes you're using AMD64, otherwise replace lib64 with lib.

Install PostGIS

Download from http://postgis.refractions.net/

cd /usr/local/src
tar xzvf /path/to/postgis-1.3.2.tar.gz
cd postgis-1.3.2
./configure --with-geos --prefix=/usr/local
make
make install

and that is all. 

Configure Posgresql

To initialize the database you need to start Postgresql:

/etc/init.d/postgresql start

Now we need to configure access to Postgresql. There are ways to do this properly, but this tutorial will not cover any of those.
For simplicity we'll let the user "postgres" have full rights to everything, without a password.

cd /var/lib/pgsql/data

[favorite text editor] pg_hba.conf

Replace

# "local" is for Unix domain socket connections only
local   all         all                               ident sameuser
# IPv4 local connections:
host    all         all         127.0.0.1/32          ident sameuser

with

# "local" is for Unix domain socket connections only
#local   all         all                               ident sameuser
local   all         postgres                               trust
# IPv4 local connections:
#host    all         all         127.0.0.1/32          ident sameuser
host    all         postgres         127.0.0.1/32          trust

You can do the same for IPv6 if you like, GeoServer uses IPv4. Then restart Postgresql

/etc/init.d/postgresql restart

and test

psql -Upostgres

Write \q and press enter to quit.

Create database "geoserver" with UTF8 support:

createdb -Upostgres -EUTF8 geoserver
createlang -Upostgres plpgsql geoserver
psql -Upostgres -d geoserver -f /usr/local/share/lwpostgis.sql
psql -Upostgres -d geoserver -f /usr/local/share/spatial_ref_sys.sql

If you have problems you can append 1>out.txt 2>err.txt to the end, which will log the ouput to text files. Otherwise, you whould now be ready to load data into you database. You can repeat the last four lines above to create new databases.

Optional, TrueType fonts

Few fonts are included with Java by default, and for most people the the official documentation falls short of a useful explanation.

It is unclear exactly where Java looks for fonts, so the easiest way to solve this problems is to copy whatever you need to a path guaranteed to be read by Java, which in our case is /opt/sun-java-1.6.0/jre/lib/fonts/

First install the fonts you want. The MS Core Fonts (Arial, Times New Roman, Verdana etc.) can be installed by following the instructions on http://corefonts.sourceforge.net/.

Now copy the .ttf files to /opt/sun-java-1.6.0/jre/lib/fonts/ , install ttmkfdir and then run it:

yum install ttmkfdir
cd /opt/sun-java-1.6.0/jre/lib/fonts/
ttmkfdir -o fonts.dir

All that remains is to restart any Java processes you have running, and the new fonts should be available.

Document generated by Confluence on Jan 16, 2008 23:27